package com.seata.stockseata.service.impl;

import com.seata.stockseata.domain.User;
import com.seata.stockseata.mapper.UserMapper;
import com.seata.stockseata.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author business
 * @since 2023-04-02
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    public Map<String, Object> saveUser(User user) {
        Map<String, Object> map = new HashMap<>();
        user.setName("李四");
        user.setSex("女");
        if (save(user)) {
            map.put("code", 200);
            map.put("message", "成功");
            map.put("data", user);
            throw new RuntimeException("失败");
        }
        return map;
    }
}
